package com.gxa.autoparts.admin.controller;

import com.gxa.autoparts.admin.service.ChartService;
import com.gxa.autoparts.core.common.JsonResult;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.Map;


/**
 * @author Bei
 * @date 2022/1/6 17:53
 */
@RestController
@RequestMapping("/chart")
public class ChartController {

    @Autowired
    ChartService chartService;

    @PostMapping("/orderCount")
    @ApiOperation("日销量折线图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime",value = "起始时间",required = false,dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name = "endTime",value = "终止时间",required = false,dataType = "Date",paramType = "query")
    })
    public Map orderCount(String startTime,String endTime) throws ParseException {
        Map map = chartService.orderByDay(startTime, endTime);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }

    @PostMapping("/orderCountByLast")
    @ApiOperation("日销量折线图未选择时间的接口")
    public Map orderCountByLast()  {
        Map map = chartService.orderByLastMonth();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }


    @PostMapping("/orderItemByLastMonth")
    @ApiOperation("分类销量饼图通用接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime",value = "起始时间",required = false,dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name = "endTime",value = "终止时间",required = false,dataType = "Date",paramType = "query")
    })
    public Map orderItemByLastMonth(String startTime,String endTime) {
        Map map = chartService.orderItemByLastMonth(startTime, endTime);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }

    @PostMapping("/userRegLastMonth")
    @ApiOperation("用户注册未选择时间的接口")
    public Map userRegLastMonth(String startTime,String endTime) throws ParseException {
        Map map = chartService.userRegLastMonth();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }

    @PostMapping("/userReg")
    @ApiOperation("用户注册选择时间的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime",value = "起始时间",required = false,dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name = "endTime",value = "终止时间",required = false,dataType = "Date",paramType = "query")
    })
    public Map userReg(String startTime,String endTime) throws ParseException {
        Map map = chartService.userReg(startTime, endTime);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }

    @PostMapping("/countPeople")
    @ApiOperation("页面访问人数（App启动量和小程序启动量）选择时间的折线图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime",value = "起始时间",required = false,dataType = "Date",paramType = "query"),
            @ApiImplicitParam(name = "endTime",value = "终止时间",required = false,dataType = "Date",paramType = "query")
    })
    public Map countPeople(String startTime,String endTime) throws ParseException {
        Map map = chartService.countPeople(startTime, endTime);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }

    @PostMapping("/countPeopleByLastMonth")
    @ApiOperation("页面访问人数（App启动量和小程序启动量）未选择时间的折线图")
    public Map countPeopleByLastMonth(){
        Map map = chartService.countPeopleByLastMonth();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(map);
        return jsonResult.getDataMap();
    }



}
